package com.xy.controller.common;

import com.xy.api.model.dto.common.UnitDTO;
import com.xy.api.model.request.common.UnitRequest;
import com.xy.api.model.response.R;
import com.xy.api.service.common.IUnitService;
import com.xy.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/unit")
public class UnitController extends BaseController {

    @Autowired
    private IUnitService unitService;

    @PostMapping("/list")
    public R queryUnitList(@RequestBody UnitRequest request) {
        List<UnitDTO> result = unitService.queryUnitList(request);
        return success(result);
    }

    @PostMapping("/detail")
    public R queryUnitDetail(@RequestBody UnitDTO request) {
        UnitDTO result = unitService.queryUnitDetail(request.getId());
        return success(result);
    }

    @PostMapping("/delete")
    public R deleteUnit(@RequestBody UnitDTO request) {
        unitService.deleteUnit(request.getId());
        return success();
    }

    @PostMapping("/edit")
    public R editUnit(@RequestBody UnitDTO request) {
        unitService.editUnit(request);
        return success();
    }

    @PostMapping("/updateExchangeRate")
    public R updateExchangeRate() {
        unitService.updateExchangeRate();
        return success();
    }

}
